/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package czStvDpds.graphics;

import czStvDpds.centrallogic.PlayerMovement;
import czStvDpds.input.LWJGLKeyEvent;
import czStvDpds.input.LWJGLKeyListener;
import czStvDpds.input.LWJGLMouseEvent;
import czStvDpds.input.LWJGLMouseListener;
import czStvDpds.movement.AbstractPlayer;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.geom.AffineTransform;

/**
 *
 * @author divad
 */
public class VisiblePlayer2D implements GraphicalPlayer2D, LWJGLKeyListener, LWJGLMouseListener {

    private AbstractPlayer player;
    private Color color;
    private Polygon playerShape;

    /**
     * vytvoří novou instanci "viditelného hráče" - nadstavba hráče, která mu
     * přidává grafické možnosti
     *
     * @param player
     */
    public VisiblePlayer2D(AbstractPlayer player) {
        this.player = player;
        color = Color.RED;
        playerShape = new Polygon(new int[]{-5, 5, 5, -5}, new int[]{-5, -5, 5, 5}, 4);
    }

////////////////// - gettery a settery - //////////////////
    /**
     * nastavení vykreslovanou barvu hráče
     *
     * @param c
     */
    public void setC(Color c) {
        this.color = c;
    }

    /**
     * vrací vykreslovanou barvu hráče
     *
     * @return
     */
    public Color getC() {
        return color;
    }

    /**
     * vrací původní instaci hráče
     *
     * @return
     */
    public AbstractPlayer getPlayer() {
        return player;
    }

/////////////////// - kresli - ///////////////////////////
    /**
     * vykreslí hráče
     *
     * @param g
     */
    @Override
    public void paint(Graphics2D g) {
        int tileSize = 25;
        AffineTransform transform = new AffineTransform();
        transform.translate(player.getX() * tileSize, player.getY() * tileSize);
        transform.rotate(Math.toRadians(player.getYaw() * -1));

        AffineTransform oldTransform = g.getTransform();
        Color oldColor = g.getColor();

        g.setTransform(transform);
        g.setColor(color);

        g.drawPolygon(playerShape);
        g.setColor(Color.darkGray);
        g.drawLine(3, 3, 8, 2);

        g.setTransform(oldTransform);
        g.setColor(oldColor);

    }
/////////////////// - listenery - ////////////////////////

    @Override
    public double getPitch() {
        return player.getPitch();
    }

    @Override
    public double getX() {
        return player.getX();
    }

    @Override
    public double getY() {
        return player.getY();
    }

    @Override
    public double getYaw() {
        return player.getYaw();
    }

    @Override
    public void keyAction(LWJGLKeyEvent e) {
        player.keyAction(e);
    }

    @Override
    public void mouseAction(LWJGLMouseEvent e) {
        player.mouseAction(e);
    }

    public void step() {
        player.step();
    }

    public void setX(double to) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setY(double to) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setYaw(double to) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setPitch(double to) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void movePlayer(PlayerMovement m, int time) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getName() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
